var layer;
var $;
var element;
var form;
var laydate;
var table;
var upload;
layui.use(['element','layer','laydate','form','table','upload'], function(){
    layer = layui.layer;
    $ = layui.jquery;
    element = layui.element;
    form = layui.form;
    laydate = layui.laydate;
    table = layui.table;
    upload = layui.upload;
    laydate.render({
        elem: '#entranceDate', //指定元素
        type: 'datetime',
        trigger: 'click' //时间时间为点击事件
    });
    laydate.render({
        elem: '#graduationDate', //指定元素
        type: 'datetime',
        trigger: 'click' //时间时间为点击事件
    });
    load();
    //监听 type状态  如何为2毕业时间不可以编译  为3可以编译
    form.on('select(type)', function(data){
        if(data.value==2){
            $("#graduationDate").attr("disabled","disabled");
        }else if(data.value==3){
            $("#graduationDate").removeAttr("disabled");
        }
    })
})
function load(){
    var avatarUrl = $("input[name=avatarUrl]").val();
    $(".img_title").attr("src",avatarUrl);
    //点击上传图片
    $("#updimga").on("click",function(){
        $("#imgbut").click();
    });
    //图片上传
    var uploadInst = upload.render({
        elem: '#imgbut',
        url: '/personnel/updImg',//改成您自己的上传接口,
        accept:'images',
        size: 5000, //限制文件大小单位 KB
        before: function (obj) {
            var developmentId = $("input[name=developmentId]").val();
            var userId = $("input[name=userId]").val();
            this.data={'developmentId':developmentId,'userId':userId}
            //预读本地文件示例
            obj.preview(function (index, file, result) {
                $('.img_title').attr('src', result); //图片链接(base64)
            });
        }, done: function (res) {
            layer.msg('更换成功', {icon: 1});
            parent.selIndexUserTab();
            //上传成功的一些操作
        }, error: function () {
            //失败
            layer.msg('更换失败', {icon: 2});
        }
    });
}
/*
*  点击编译  开始编译
* */
function updThinkUserInfo(){
    layer.msg("开始编译", {icon: 1});
    $(".nickname_input").removeAttr("disabled");
    $(".studentNumber_input").removeAttr("disabled");
    $(".realName_input").removeAttr("disabled");
    $(".profession_input").removeAttr("disabled");
    $("#entranceDate").removeAttr("disabled");
    $(".idCard_input").removeAttr("disabled");
    $(".phone_input").removeAttr("disabled");
    $(".email_input").removeAttr("disabled");
    $(".studyContent_textarea").removeAttr("disabled");
    $("#select_id").attr("style","display:block");
    $("#select_id2").attr("style","display:none");
    $("#type_select_id").attr("style","display:block");
    $("#type_select_id2").attr("style","display:none");
    $("#div_p_uplo").attr("style","display:block");
    $(".upd_btn").removeAttr("onclick");
    $(".upd_btn").attr("onclick","submitUpdInfo()");
    $(".upd_btn").val("提交");
}
function submitUpdInfo(){
    var form = $("#selupdInfo").serialize();
    var developmentId = $("input[name=developmentId]").val();
    var create=localStorage.getItem("user");
    create=JSON.parse(create);//将获取json字符串转json对象
    var updateId = create.user_id;
    form+="&developmentId="+developmentId;
    form+="&updateId="+updateId;
    $.ajax({
        url:"/personnel/updThinkInfo",
        type:"post",
        dataType:"json",
        data:form,
        success:function(item) {
            var tablename = "进思用户数据列表";
            var type=4;
            var remark = developmentId+"";
            addOperLog(tablename,type,remark);
            if(item){
                window.parent.selIndexUserTab();
                var layer1 = parent.layer;
                parent.layer.close(layer1.index);
                parent.layer.msg("编译成功", {icon: 1});
            }else{
                layer.msg("编译失败", {icon: 2});
            }
        }
    })
    $(".upd_btn").removeAttr("onclick");
    $(".upd_btn").attr("onclick","updThinkUserInfo()");
    $(".upd_btn").val("编译");
    $(".nickname_input").attr("disabled","disabled");
    $(".studentNumber_input").attr("disabled","disabled");
    $(".realName_input").attr("disabled","disabled");
    $(".profession_input").attr("disabled","disabled");
    $("#entranceDate").attr("disabled","disabled");
    $("#graduationDate").attr("disabled","disabled");
    $(".idCard_input").attr("disabled","disabled");
    $(".phone_input").attr("disabled","disabled");
    $("#select_id").attr("style","display:none");
    $("#select_id2").attr("style","display:block");

    $("#type_select_id").attr("style","display:none");
    $("#type_select_id2").attr("style","display:block");
    $("#div_p_uplo").attr("style","display:none");
    $(".email_input").attr("disabled","disabled");
    $(".studyContent_textarea").attr("disabled","disabled");
}
/**
 *  点击 取消关闭弹出层
 */
function closeLayer(){
    var layer=parent.layer;
    layer.close(layer.index);
}
/**
 *  添加后台操作日志
 * */
function addOperLog(tablename,type,remark){
    var create=localStorage.getItem("user");
    create=JSON.parse(create);//将获取json字符串转json对象
    var mid = create.user_id;
    form+="&mid="+mid;
    form+="&tablename="+tablename;
    form+="&type="+type;
    form+="&remark="+remark;
    $.post("/personnel/addOperationLog", form, function (res) {
        form="";
    });
}